package com.itcast;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Created by cc
 * Description:
 * User: CZH
 * Date: 2023-02-10
 * Time: 13:53
 */
public class Test {

    public static void main(String[] args) {
        String ran = "aa";
        String mag = "baa";
        System.out.println(canConstruct(ran, mag));
    }
    public static boolean canConstruct(String ransomNote, String magazine) {
        // 创建个新数组，有 26 个元素位置
        int[] arr = new int[26];
        // 创建变量 i，遍历字符串 magazine
        int i = 0;
        for (i=0; i<magazine.length(); i++) {
            // 取 magazine 字符串的头元素 tmp，减去 'a'，得出该放在哪个元素位置
            int tmp = magazine.charAt(i) - 'a';
            arr[tmp] += 1;
        }
        // 创建变量 j，遍历字符串 ransomNote
        int j = 0;
        for (j=0; j<ransomNote.length(); j++) {
            // 取 ransomNote 字符串的头元素 tmp，减去 'a'，再减去新数组中该元素的个数。
            int tmp = ransomNote.charAt(j) - 'a';
            arr[tmp] -= 1;
            // 然后判断，是否会遇到新数组中元素为 -1 的情况，遇到就是 false
            if (arr[tmp] < 0) {
                return false;
            }
        }
        // 最后遍历结束，结果为 true
        return true;
    }


    public static void main22(String[] args) {
        List<String> list = fizzBuzz(15);
        for (String s : list) {
            System.out.print(s + " ");
        }
    }
    public static List<String> fizzBuzz(int n) {
        List<String> list = new ArrayList<>();
        for (int i = 1; i <= n; i++) {
            if ((i%3==0) && (i%5==0)) {
                list.add("FizzBuzz");
            }else if (i%5==0) {
                list.add("Buzz");
            }else if (i%3==0) {
                list.add("Fizz");
            }else {
                list.add(Integer.toString(i));
            }
        }
        return list;
    }

    public static void main21(String[] args) {
        int[][] acc = new int[][]{{1,2,3},{3,2,1}};
        System.out.println(maximumWealth(acc));
    }
    public static int maximumWealth(int[][] accs) {
        int max = Integer.MIN_VALUE;
        for(int[] acc : accs) {
            max = Math.max(max, Arrays.stream(acc).sum());
        }
        return max;
    }

    public static void main20(String[] args) {
        int num = 14;
        int i = numberOfSteps(num);
        System.out.println(i);
    }


    public static int numberOfSteps(int num) {  //14
        int ret = 0;
        while(num != 0) {
            ret++;
//            (num % 2 == 0) ? (num >>= 1) : (num -= 1);
            if(num % 2 == 0) {
                num >>= 1;
            }else if (num % 2 == 1) {
                num -= 1;
            }
        }
        return ret;
    }


    public static int[] runningSum(int[] nums) {
        for (int i=1; i<nums.length; i++) {
            nums[i] = nums[i-1] + nums[i];
        }
        return nums;
    }

    public static void main19(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum = 0;
        while (sc.hasNextInt()) {
            int tmp = sc.nextInt();
            sum += tmp;
        }
        System.out.println(sum);
    }

    //1! + 2! + 3! + 4! + 5!
    public static void main18(String[] args) {
        int count = 0;
        for (int i = 1; i < 6; i++) {
            int ret = 1;
            for (int j = 1; j <= i; j++) {
                ret *= j;
            }
            count += ret;
        }
        System.out.println(count);
    }

    public static void main17(String[] args) {
        int i = 1;
        int j = 0;
        while (i <= 5) {
            int count = 1;
            int n = 1;
            while (n <= i) {
                count *= n;
                n++;
            }
            j += count;
            i++;
        }
        System.out.println(j);
    }

    public static void main16(String[] args) {
        int count = 1;
        int n = 1;
        while (n <= 5) {
            count *= n;
            n++;
        }
        System.out.println(count);
    }

    public static void main15(String[] args) {
        int count = 0;
        int n = 1;
        while (n <= 100) {
            count += n;
            n++;
        }
        System.out.println(count);
    }

    public static void main14(String[] args) {
        int num = 1;
        while (num < 5) {
            System.out.println(num);
            num++;
        }
    }

    public static void main13(String[] args) {
        int year = 2000;
        if ((year % 4 == 0) || (year % 100 == 0 && year % 400 == 0)) {
            System.out.println("yes");
        } else {
            System.out.println("no");
        }
    }

    public static void main12(String[] args) {
        int a = 0xf;
        System.out.printf("%x\n", ~a);
    }

    /*
    * 输入任意一种物质，要求输出其每种元素的数量。
    比如
    输入 CaCO3，其组成分别为 Ca：1，C：1，O：3，输出 Ca1C1O3
    输入 Fe2(SO4)3，其组成分别为 Fe：2，S：3，O：12，输出 Fe2S3O12
    （注意：元素名称首字母大写，剩余字母都小写；括号括起来表示括号中的结构作
    为整体出现多少次）
    * */
    public static void main11(String[] args) {
        List<Character> list = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        // 1.截取字符串首字母，判断是否是大写
        //      大写则分配空间存储
        // 3.判断下一个字符

    }

    public static void main10(String[] args) {
        /*
        * byte  1
        * short 2
        * int   4
        * long  8
        *
        * float 4
        * double8
        *
        * char  2
        *
        * boolean1
        * */
    }

    public static void main9(String[] args) {
        int a = 10;
        String b = a + "1";
        String c = String.valueOf(a);
        System.out.println(b.equals(c));
        Integer value = Integer.valueOf(b);
        int i = Integer.parseInt(b);
        System.out.println(value == i);
    }

    public static void main8(String[] args) {
        byte a = 10;
        byte b = 20;
        int c = a + b;
        System.out.println(c);
    }

    public static void main7(String[] args) {
        short a = 10;
        short b = 20;
        int c = a + b;
        System.out.println(c);
    }

    public static void main6(String[] args) {
        int a = 10;
        double b = 20.0;
        double c = a + b;
        System.out.println(c);
    }

    public static void main5(String[] args) {
        float a = 1.0f;
        System.out.println(a);
        System.out.println(Float.MAX_EXPONENT);
        System.out.println(Float.MIN_EXPONENT);
        System.out.println(Short.MAX_VALUE);
        System.out.println(Byte.MAX_VALUE);
    }

    public static void main4(String[] args) {
        double a1 = 1.1;
        System.out.println(a1*a1);
        int a = 1;
        int b = 2;
        System.out.println(a/b);
    }

    public static void main3(String[] args) {
        long a = 10L;
        System.out.println(a);
        System.out.println(Long.MIN_VALUE);
        System.out.println(Long.MAX_VALUE);
    }

    public static void main2(String[] args) {
        int a = 10;
        System.out.println(a);
        /*
        * 8bit = 1byte
        * 1024byte = 1kb
        * 1024kb = 1 mb
        * 1024mb = 1 gb
        * 1024gb = 1 tb
        * */
        System.out.println(Integer.MAX_VALUE+1);
        System.out.println(Integer.MIN_VALUE-1);
    }

    public static void main1(String[] args) {
        System.out.println("1");
    }
}
